<template>
  <a-modal title='职务结算政策' v-if='modalVisible' :visible='modalVisible' :dialog-style="{ top: '10px' }" width='800px' :body-style='bodyStyle' @cancel='handleCancel' @ok='handleSubmit'>
    <f-form ref='form' :action='api.bpp' :form-key='this.formItem.policyPositionId' @success='handleCancel'>
      <f-form-item label='职务' type='select' name='positionId' required :showSearch='true' :data='api.position.list' label-key='positionName' value-key='positionId' :value='formItem.positionId' />
      <f-form-item label='结算价取值' type='radio' name='priceType' :required='true' dataType='number' :data='api.busCommon.priceType' :value.sync='formItem.priceType' />
      <f-form-item label='结算价' name='positionPrice' v-if='formItem.priceType==1' type='number' :precision='3' data-type='number' required :value='formItem.positionPrice' />
      <f-form-item label='最高加价' name='makeUpPrice' v-if='formItem.priceType==1' type='number' :precision='3' data-type='number' required :value='formItem.makeUpPrice' />
      <f-form-item label='结算标准' name='positionRate' tooltip='格式用小数表示,示例值0.18' type='number' required :precision='3' data-type='number' :value='formItem.positionRate' />
      <f-form-item label='结算公式' placeholder='请选择结算公式' name='positionSettleFormula' :readOnly='true' :value.sync='formItem.positionSettleFormula' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择公式'>
          <a-icon type='calculator' style='cursor:pointer' @click='openFormulaModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label='开始日期' name='beginDate' type='date' required :value='formItem.beginDate' />
      <f-form-item label='结束日期' name='endDate' type='date' :value='formItem.endDate' />
      <f-form-item label='备注' name='remark' :value='formItem.remark' />
    </f-form>
    <select-formula-modal ref='formulaModal' @onSelectChange='onSelectFormulaChange'></select-formula-modal>
  </a-modal>
</template>
<script>
import api from "../../../../js/api"
import SelectFormulaModal from "../../../../components/select_formula_modal"

export default {
  name: "policyPositionForm",
  props: {
    policyDrugId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      formModal: false,
      fileIds: [],//上传文件ID
      loaded: false,//是否加载完成
      modalVisible: false,
      params1: {
        formulaType: 6
      },
      params2: {
        formulaType: 3
      },
      bodyStyle: {
        height: "530px",
        overflow: "hidden",
        overflowY: "scroll"
      },
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        policyPositionId: "",
        positionId: "",
        positionPrice: "",
        positionRate: "",
        beginDate: "",
        positionSettleFormula: "",
        endDate: "",
        remark: ""
      }
    },
    openModal(data) {
      this.isEdit = false
      if (data && data.policyPositionId) {
        this.isEdit = true
        this.formItem = data
      } else {
        this.formItem = {}
      }
      this.modalVisible = true
    },
    handleCancel() {
      this.modalVisible = false
    },
    /**
     * 选择公式
     */
    openFormulaModal() {
      this.$refs["formulaModal"].open({
        formulaType: 3
      })
    },
    /**
     * 公式选择回调
     */
    onSelectFormulaChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "positionSettleFormula": selectedRows[0].formulaContent })
      this.formItem.positionSettleFormula = selectedRows[0].formulaContent
    },
    //提交表单
    handleSubmit() {
      this.$refs.form.submit({ policyDrugId: this.policyDrugId }, () => {
        this.$emit("success")
      })
    }
  },
  created() {
  },
  components: { SelectFormulaModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
